package com.nit.generate;

import com.nit.dto.TangPoetryDTO;
import com.nit.tools.NitResourceUtils;
import com.nit.tools.json.NitJsonTools;
import com.nit.tools.loop.NitLoopTools;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 中国文化(唐诗) 生成器
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @link: 1715656022@qq.com
 * @Date: 2023-07-26
 */
@Slf4j
public class NitChinaLanguageGenerator {
    private final static List<TangPoetryDTO> tangPoetryDTOList;
    private final static List<String> idiomList;

    static {
        //加载唐诗json文件
        tangPoetryDTOList = NitJsonTools.parseObjectList(NitResourceUtils.readString("tang-poetry.json"), TangPoetryDTO.class);
        //加载成语txt
        idiomList = NitResourceUtils.readLines("idiom.txt");
    }

    public static void main(String[] args) {
        NitLoopTools.loop(4, () -> {
            TangPoetryDTO tmp = NitChinaLanguageGenerator.generateTangPoetry();
            System.out.println("随机唐诗:" + tmp + "<br>");
        });
        NitLoopTools.loop(4, () -> {
            String tmp = NitChinaLanguageGenerator.generateIdiom();
            System.out.println("随机成语:" + tmp + "<br>");
        });
    }

    /**
     * 唐诗 生成器
     */
    public static TangPoetryDTO generateTangPoetry() {
        return tangPoetryDTOList.get(NitNumberGenerator.generateInt(0, tangPoetryDTOList.size()));
    }

    /**
     * 成语 生成器
     */
    public static String generateIdiom() {
        return idiomList.get(NitNumberGenerator.generateInt(0, idiomList.size()));
    }

}
